home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Interfaces & Libraries / Interfaces / CIncludes / Threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-06  |  9.0 KB  |  230 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Threads.h
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1 in “MPW Latest” on ETO #18
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __THREADS__
  21. #define __THREADS__
  22.  
  23.  
  24. #ifndef __ERRORS__
  25. #include <Errors.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __MEMORY__
  30. #include <Memory.h>
  31. #endif
  32. /*    #include <Types.h>                                            */
  33. /*    #include <MixedMode.h>                                        */
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #if PRAGMA_ALIGN_SUPPORTED
  40. #pragma options align=mac68k
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT_SUPPORTED
  44. #pragma import on
  45. #endif
  46.  
  47. typedef unsigned short ThreadState;
  48.  
  49.  
  50. enum {
  51.     kReadyThreadState            = 0,
  52.     kStoppedThreadState            = 1,
  53.     kRunningThreadState            = 2
  54. };
  55.  
  56. /* Error codes have been meoved to Errors.(pah) */
  57. /* Thread environment characteristics */
  58. typedef void *ThreadTaskRef;
  59.  
  60. /* Thread characteristics */
  61. typedef unsigned long ThreadStyle;
  62.  
  63.  
  64. enum {
  65.     kCooperativeThread            = 1L << 0,
  66.     kPreemptiveThread            = 1L << 1
  67. };
  68.  
  69. /* Thread identifiers */
  70. typedef unsigned long ThreadID;
  71.  
  72.  
  73. enum {
  74.     kNoThreadID                    = 0,
  75.     kCurrentThreadID            = 1,
  76.     kApplicationThreadID        = 2
  77. };
  78.  
  79. /* Options when creating a thread */
  80. typedef unsigned long ThreadOptions;
  81.  
  82.  
  83. enum {
  84.     kNewSuspend                    = (1 << 0),
  85.     kUsePremadeThread            = (1 << 1),
  86.     kCreateIfNeeded                = (1 << 2),
  87.     kFPUNotNeeded                = (1 << 3),
  88.     kExactMatchThread            = (1 << 4)
  89. };
  90.  
  91. /* Information supplied to the custom scheduler */
  92. struct SchedulerInfoRec {
  93.     unsigned long                    InfoRecSize;
  94.     ThreadID                        CurrentThreadID;
  95.     ThreadID                        SuggestedThreadID;
  96.     ThreadID                        InterruptedCoopThreadID;
  97. };
  98. typedef struct SchedulerInfoRec SchedulerInfoRec;
  99.  
  100. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  101.  
  102. #if GENERATING68K && GENERATINGCFM
  103. /*
  104.     The following UniversalProcPtrs are for CFM-68k compatiblity with
  105.     the implementation of the Thread Manager.
  106. */
  107. typedef UniversalProcPtr ThreadEntryProcPtr;
  108.  
  109. typedef UniversalProcPtr ThreadSchedulerProcPtr;
  110.  
  111. typedef UniversalProcPtr ThreadSwitchProcPtr;
  112.  
  113. typedef UniversalProcPtr ThreadTerminationProcPtr;
  114.  
  115. typedef UniversalProcPtr DebuggerNewThreadProcPtr;
  116.  
  117. typedef UniversalProcPtr DebuggerDisposeThreadProcPtr;
  118.  
  119. typedef UniversalProcPtr DebuggerThreadSchedulerProcPtr;
  120.  
  121. enum {
  122.     uppThreadEntryProcInfo = kPascalStackBased
  123.          | RESULT_SIZE(SIZE_CODE(sizeof(void*)))
  124.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  125.     uppThreadSchedulerProcInfo = kPascalStackBased
  126.          | RESULT_SIZE(SIZE_CODE(sizeof(ThreadID)))
  127.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SchedulerInfoRecPtr))),
  128.     uppThreadSwitchProcInfo = kPascalStackBased
  129.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID)))
  130.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void*))),
  131.     uppThreadTerminationProcInfo = kPascalStackBased
  132.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID)))
  133.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void*))),
  134.     uppDebuggerNewThreadProcInfo = kPascalStackBased
  135.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID))),
  136.     uppDebuggerDisposeThreadProcInfo = kPascalStackBased
  137.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID))),
  138.     uppDebuggerThreadSchedulerProcInfo = kPascalStackBased
  139.          | RESULT_SIZE(SIZE_CODE(sizeof(ThreadID)))
  140.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SchedulerInfoRecPtr)))
  141. };
  142. #define NewThreadEntryProc(userRoutine)                (ThreadEntryProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadEntryProcInfo, GetCurrentArchitecture())
  143. #define NewThreadSchedulerProc(userRoutine)            (ThreadSchedulerProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadSchedulerProcInfo, GetCurrentArchitecture())
  144. #define NewThreadSwitchProc(userRoutine)            (ThreadSwitchProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadSwitchProcInfo, GetCurrentArchitecture())
  145. #define NewThreadTerminationProc(userRoutine)        (ThreadTerminationProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadTerminationProcInfo, GetCurrentArchitecture())
  146. #define NewDebuggerNewThreadProc(userRoutine)        (DebuggerNewThreadProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerNewThreadProcInfo, GetCurrentArchitecture())
  147. #define NewDebuggerDisposeThreadProc(userRoutine)    (DebuggerDisposeThreadProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerDisposeThreadProcInfo, GetCurrentArchitecture())
  148. #define NewDebuggerThreadSchedulerProc(userRoutine)    (DebuggerThreadSchedulerProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerThreadSchedulerProcInfo, GetCurrentArchitecture())
  149. #else
  150. /*
  151.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  152.     of differences between 680x0 and PowerPC runtime architectures with regard to
  153.     the implementation of the Thread Manager.
  154.  */
  155. /* Prototype for thread's entry (main) routine */
  156. typedef void *voidPtr;
  157.  
  158. typedef pascal voidPtr (*ThreadEntryProcPtr)(void *threadParam);
  159. /* Prototype for custom thread scheduler routine */
  160. typedef pascal ThreadID (*ThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  161. /* Prototype for custom thread switcher routine */
  162. typedef pascal void (*ThreadSwitchProcPtr)(ThreadID threadBeingSwitched, void *switchProcParam);
  163. /* Prototype for thread termination notification routine */
  164. typedef pascal void (*ThreadTerminationProcPtr)(ThreadID threadTerminated, void *terminationProcParam);
  165. /* Prototype for debugger NewThread notification */
  166. typedef pascal void (*DebuggerNewThreadProcPtr)(ThreadID threadCreated);
  167. /* Prototype for debugger DisposeThread notification */
  168. typedef pascal void (*DebuggerDisposeThreadProcPtr)(ThreadID threadDeleted);
  169. /* Prototype for debugger schedule notification */
  170. typedef pascal ThreadID (*DebuggerThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  171. #endif
  172. extern pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  173.  THREEWORDINLINE(0x303C, 0x0501, 0xABF2);
  174. extern pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  175.  THREEWORDINLINE(0x303C, 0x0402, 0xABF2);
  176. extern pascal OSErr GetSpecificFreeThreadCount(ThreadStyle threadStyle, Size stackSize, short *freeCount)
  177.  THREEWORDINLINE(0x303C, 0x0615, 0xABF2);
  178. extern pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  179.  THREEWORDINLINE(0x303C, 0x0413, 0xABF2);
  180. extern pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  181.  THREEWORDINLINE(0x303C, 0x0414, 0xABF2);
  182. extern pascal OSErr NewThread(ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade)
  183.  THREEWORDINLINE(0x303C, 0x0E03, 0xABF2);
  184. extern pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  185.  THREEWORDINLINE(0x303C, 0x0504, 0xABF2);
  186. extern pascal OSErr YieldToThread(ThreadID suggestedThread)
  187.  THREEWORDINLINE(0x303C, 0x0205, 0xABF2);
  188. extern pascal OSErr YieldToAnyThread(void)
  189.  FOURWORDINLINE(0x42A7, 0x303C, 0x0205, 0xABF2);
  190. extern pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  191.  THREEWORDINLINE(0x303C, 0x0206, 0xABF2);
  192. extern pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  193.  THREEWORDINLINE(0x303C, 0x0407, 0xABF2);
  194. extern pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  195.  THREEWORDINLINE(0x303C, 0x0508, 0xABF2);
  196. extern pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  197.  THREEWORDINLINE(0x303C, 0x0512, 0xABF2);
  198. extern pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  199.  THREEWORDINLINE(0x303C, 0x0209, 0xABF2);
  200. extern pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  201.  THREEWORDINLINE(0x303C, 0x070A, 0xABF2);
  202. extern pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  203.  THREEWORDINLINE(0x303C, 0x0611, 0xABF2);
  204. extern pascal OSErr ThreadBeginCritical(void)
  205.  THREEWORDINLINE(0x303C, 0x000B, 0xABF2);
  206. extern pascal OSErr ThreadEndCritical(void)
  207.  THREEWORDINLINE(0x303C, 0x000C, 0xABF2);
  208. extern pascal OSErr SetDebuggerNotificationProcs(DebuggerNewThreadProcPtr notifyNewThread, DebuggerDisposeThreadProcPtr notifyDisposeThread, DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  209.  THREEWORDINLINE(0x303C, 0x060D, 0xABF2);
  210. extern pascal OSErr GetThreadCurrentTaskRef(ThreadTaskRef *threadTRef)
  211.  THREEWORDINLINE(0x303C, 0x020E, 0xABF2);
  212. extern pascal OSErr GetThreadStateGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  213.  THREEWORDINLINE(0x303C, 0x060F, 0xABF2);
  214. extern pascal OSErr SetThreadReadyGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToSet)
  215.  THREEWORDINLINE(0x303C, 0x0410, 0xABF2);
  216.  
  217. #if PRAGMA_IMPORT_SUPPORTED
  218. #pragma import off
  219. #endif
  220.  
  221. #if PRAGMA_ALIGN_SUPPORTED
  222. #pragma options align=reset
  223. #endif
  224.  
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228.  
  229. #endif /* __THREADS__ */
  230.